<?php

namespace Dms\Controller;
use Think\Controller;
class WebconfController extends Controller
{

	/**
	 * [group description]
	 * @return [type] [description]
	 */
	public function group()
	{
		if(IS_POST)
		{
			$data['pcLogo']        = I('POST.pcLogo');
			$data['mobileLogo']    = I('POST.mobileLogo');
			$data['companyName']   = I('POST.companyName');
			$data['companyPhone']  = I('POST.companyPhone');
			$data['recordCode']    = I('POST.recordCode');
			$data['copyRight']     = I('POST.copyRight');
			$data['companyQRcode'] = I('POST.companyQRcode');

			$result = M3('web_conf_companyinfo')->where(array('id'=>'1'))->save($data);
			if($result != false)
			{
				$Log = new \Model\Log();
				$Log->webconfOperation(M3('web_conf_companyinfo')->getLastSql());
				$this->success('保存成功');
			}
			else
			{
				$this->error('保存失败');
			}
			exit();
		}
		$list           = M2('web_conf_group')->where(array('pId'=>0))->order('sort')->select();

		foreach ($list as $key => $value)
		{
			$list[$key]['child'] = M2('web_conf_group')->where(array('pId'=>$value['id']))->order('sort')->select();
		}

		$this->list     = $list;

		$this->info = M2('web_conf_companyinfo')->where(array('id'=>'1'))->find();

		$this->linklist = M2('web_conf_shortlink')->order('id DESC')->select();

		$this->menuID   = '156';
		$this->menuName = '网站前端配置';
		$this->display();
	}


	public function getshortlink()
	{
		$return = array('valid'=>false,'state'=>'请稍后重试。。。');
		if(IS_POST)
		{
			$type   = I('post.type');
			$webUrl = trim(I('post.webUrl',''));
			switch ($type)
			{
				case 'add':
					$data['webUrl'] = $webUrl;
					$data['shortlink']  = trim(I('post.shortlink',''));
					$data['createTime'] = time();

					$result = M3('web_conf_shortlink')->add($data);

					if($result != false)
					{
						$return = array('valid'=>true,'state'=>'编辑成功');
					}
					else
					{
						$return['state'] = '编辑失败';
					}
					break;
				default:

					if(strpos($webUrl, 'm.tripvip.cn') || strpos($webUrl, 'www.tripvip.cn'))
					{
						$group = 'http://m.tripvip.cn/';
					}
					else
					{
						$return['state'] = '请输入正确的链接地址。。。';
						$this->ajaxReturn($return);
					}
					if(strpos($webUrl, 'mobile/'))
					{
						$group = 'http://m.tripvip.cn/';
					}
					else
					{
						$group = 'http://www.tripvip.cn/';
					}
					$arr = array('http://','www.tripvip.cn/','m.tripvip.cn/','mobile/','center/','.html');
					$len = count($arr);
					for ($i=0; $i < $len; $i++)
					{
						$webUrl = str_replace($arr[$i],'',$webUrl);
					}
					$action = substr($webUrl, 0,1);
					$method = randNums();
					$shortlink = $group.$action.'/'.$method;
					$row = M2('web_conf_shortlink')->where(array('shortlink'=>$shortlink))->find();
					if(empty($row) == true)
					{	
						$return = array('valid'=>true,'state'=>'SUCCESS');
						$return['info']['shortlink'] = $shortlink;
					}
					else
					{
						$return['state'] = '此短链接有重复，请重新生成。。。';
					}

					break;
			}
		}
		else
		{
			$return['state'] = '请求出错。。。';
		}
		// echo json_encode($return);
		$this->ajaxReturn($return);
	}
	/**
	 * [info description]
	 * @return [type] [description]
	 */
	public function info()
	{
		$id = I('get.id');
		$group = M2('web_conf_group')->where(array('id'=>$id))->find();
		if($group != false)
		{
			$this->redirect(MODULE_NAME.'/Webconf/'.$group['action']);
		}
		else
		{
			$this->redirect(MODULE_NAME.'/Webconf/group');
			exit();
		}

	}

	/**
	 * [mobilehome description]
	 * @return [type] [description]
	 */
	public function mobilehome()
	{

		$step = I('get.step');
		$this->step = $step;
		switch ($step)
		{
			case '1':
				$speciallist =    M2('web_conf_mobilehome_special')->where(array('status'=>array('neq','-1')))->order(array('status'=>'DESC','sort'=>'ASC'))->select();
				foreach ($speciallist as $key => $value)
				{
					$speciallist[$key]['startDate'] = $this->timetodate($value['startTime'],'Y-m-d');
					$speciallist[$key]['endDate']   = $this->timetodate($value['endTime'],'Y-m-d');
				}
				$this->speciallist = $speciallist;

				break;
			case '2':
				$recommendlist = M2('web_conf_mobilehome_recommend')->where(array('status'=>array('neq','-1')))->order(array('status'=>'DESC','sort'=>'ASC'))->select();
				foreach ($recommendlist as $key => $value)
				{
					$recommendlist[$key]['startDate'] = $this->timetodate($value['startTime'],'Y-m-d');
					$recommendlist[$key]['endDate']   = $this->timetodate($value['endTime'],'Y-m-d');

					$productRow                       = M2('pack_product_travel')->where(array('id'=>$value['productID']))->find();
					$recommendlist[$key]['title']     = $productRow['title'];
					$recommendlist[$key]['imagesUrl'] = imgUrlComplete($productRow['mobileBigPic']);
				}
				$this->recommendlist = $recommendlist;
				break;
			case '3':
				$destinationlist = M2('web_conf_mobilehome_destination')->where(array('status'=>array('neq','-1')))->order(array('status'=>'DESC','sort'=>'ASC'))->select();
				foreach ($destinationlist as $key => $value)
				{
					$destinationlist[$key]['startDate'] = $this->timetodate($value['startTime'],'Y-m-d');
					$destinationlist[$key]['endDate']   = $this->timetodate($value['endTime'],'Y-m-d');

					$destinationlist[$key]['title'] = M2('destination')->where(array('id'=>$value['destinationID']))->getField('name');
					$destinationlist[$key]['imagesUrl'] = M2('destination_detail')->where(array('destination'=>$value['destinationID'],'pid'=>'5'))->getField('bigPic');
				}

				$this->destinationlist = $destinationlist;
				break;
			case '4':
				$partnerlist = M2('web_conf_mobilehome_partner')->where(array('status'=>array('neq','-1')))->order(array('status'=>'DESC','sort'=>'ASC'))->select();
				$this->partnerlist = $partnerlist;

				break;
			case '5':
				$profilelist = M2('web_conf_mobilehome_profile')->where(array('status'=>array('neq','-1')))->order(array('status'=>'DESC','sort'=>'ASC'))->select();
				$this->profilelist = $profilelist;
				break;
			case '6':
				$columnlist = M2('web_conf_mobilehome_column')->where(array('status'=>array('neq','-1')))->order(array('status'=>'DESC','sort'=>'ASC'))->select();
				$this->columnlist = $columnlist;
				break;

			default:
				$bannerlist = M2('web_conf_mobilehome_banner')->where(array('status'=>array('neq','-1')))->order(array('status'=>'DESC','sort'=>'ASC'))->select();
				foreach ($bannerlist as $key => $value)
				{
					$bannerlist[$key]['startDate'] = $this->timetodate($value['startTime'],'Y-m-d');
					$bannerlist[$key]['endDate']   = $this->timetodate($value['endTime'],'Y-m-d');
				}
				$this->bannerlist = $bannerlist;
				break;
		}

		$this->menuID   = '156';
		$this->menuName = '网站前端配置-移动端首页';
		$this->display($group['action']);
	}

	/**
	 * [mobilehomecolumnstyle description]
	 * @return [type] [description]
	 */
	public function mobilehomecolumnstyle()
	{
		$id = I('get.id');
		$this->id = $id;
		$columnRow = M2('web_conf_mobilehome_column')->where(array('id'=>$id))->find();
		if($columnRow == false)$this->error('此栏目不存在！');
		$columnRow['parent'] = M2('web_conf_mobilehome_column_main')->where(array('columnID'=>$columnRow['id'],'type'=>$columnRow['type']))->order('sort')->select();
		foreach ($columnRow['parent'] as $kp => $vp)
		{
			$columnRow['parent'][$kp]['child'] = M2('web_conf_mobilehome_column_info')->where(array('mainID'=>$vp['id']))->select();
			foreach ($columnRow['parent'][$kp]['child'] as $kc => $vc)
			{
				$productRow = M2('pack_product_travel')->field('price,categoryInterestID')->where(array('id'=>$vc['productID']))->find();
				$columnRow['parent'][$kp]['child'][$kc]['price'] = $productRow['price'];

				$categoryInterestArr = explode('|', $productRow['categoryInterestID']);
				$labelCount          = count($categoryInterestArr);
				$labelNameArr        = array();
				for ($i=0; $i < $labelCount; $i++)
				{
					$labelNameArr[$i] = M2('label_class')->where(array('id'=>$categoryInterestArr[$i]))->getField('name');

				}

				$columnRow['parent'][$kp]['child'][$kc]['labelName'] = implode('|',$labelNameArr);
				unset($categoryInterestArr);
				unset($labelNameArr);
				switch ($vc['sign'])
				{
					case '1':
						$signName = '新品';
						break;
					case '2':
						$signName = '爆款';
						break;
					case '3':
						$signName = '特价';
						break;
				}

				$columnRow['parent'][$kp]['child'][$kc]['signName']  = $signName;
				unset($signName);

				if(empty($columnRow['parent'][$kp]['child'][$kc]['wenUrl']) == true && empty($columnRow['parent'][$kp]['child'][$kc]['productID']) == false)
				{
					$columnRow['parent'][$kp]['child'][$kc]['wenUrl'] = "http://www.tripvip.cn/center/product/details/id/".$columnlist[$key]['parent'][$kp]['child'][$kc]['productID'].".html";
				}
				unset($productRow);
			}
		}
		$this->columnRow = $columnRow;

		$this->menuID   = '156';
		$this->menuName = '移动端栏目模板——'.$columnRow['name'];
		$this->display();
	}


	/**
	 * [mobilehome description]
	 * @return [type] [description]
	 */
	public function mobilehomePost()
	{
		$return = array('valid'=>false,'state'=>'请稍后重试。。。');
		if(IS_POST)
		{
			$type = I('post.type');
			switch ($type)
			{
				case 'banner':
					$id                = I('post.id');
					$data['title']     = I('post.title');
					$data['imagesUrl'] = I('post.imagesUrl');
					$data['webUrl']    = I('post.webUrl');
					$data['startTime'] = strtotime(I('post.startTime'));
					$data['endTime']   = strtotime(I('post.endTime'));
					if(empty($id) == true)
					{
						$data['createTime'] = time();
						$result = M3('web_conf_mobilehome_banner')->add($data);
					}
					else
					{
						$result = M3('web_conf_mobilehome_banner')->where(array('id'=>$id))->save($data);
					}

					$table = 'web_conf_mobilehome_banner';
					break;

				case 'special':
					$id                = I('post.id');
					$data['title']     = I('post.title');
					$data['imagesUrl'] = I('post.imagesUrl');
					$data['webUrl']    = I('post.webUrl');
					$data['startTime'] = strtotime(I('post.startTime'));
					$data['endTime']   = strtotime(I('post.endTime'));
					if(empty($id) == true)
					{
						$data['createTime'] = time();
						$result = M3('web_conf_mobilehome_special')->add($data);
					}
					else
					{
						$result = M3('web_conf_mobilehome_special')->where(array('id'=>$id))->save($data);
					}

					$table = 'web_conf_mobilehome_special';
					break;

				case 'recommend':
					$id                = I('post.id');
					$data['productID'] = I('post.productID');
					$data['startTime'] = strtotime(I('post.startTime'));
					$data['endTime']   = strtotime(I('post.endTime'));
					if(empty($id) == true)
					{
						$data['createTime'] = time();
						$result = M3('web_conf_mobilehome_recommend')->add($data);
					}
					else
					{
						$result = M3('web_conf_mobilehome_recommend')->where(array('id'=>$id))->save($data);
					}

					$table = 'web_conf_mobilehome_recommend';
					break;

				case 'destination':
					$id                    = I('post.id');
					$data['destinationID'] = I('post.destinationID');
					$data['bgColor'] 	   = I('post.bgColor');
					$data['startTime']     = strtotime(I('post.startTime'));
					$data['endTime']       = strtotime(I('post.endTime'));
					if(empty($id) == true)
					{
						$data['createTime'] = time();
						$result = M3('web_conf_mobilehome_destination')->add($data);
					}
					else
					{
						$result = M3('web_conf_mobilehome_destination')->where(array('id'=>$id))->save($data);
					}

					$table = 'web_conf_mobilehome_destination';
					break;

				case 'partner':
					$id                = I('post.id');
					$data['title']     = I('post.title');
					$data['imagesUrl'] = I('post.imagesUrl');
					$data['webUrl']    = I('post.webUrl');
					if(empty($id) == true)
					{
						$data['createTime'] = time();
						$result = M3('web_conf_mobilehome_partner')->add($data);
					}
					else
					{
						$result = M3('web_conf_mobilehome_partner')->where(array('id'=>$id))->save($data);
					}

					$table = 'web_conf_mobilehome_partner';
					break;

				case 'columnMain':
					$id                = I('post.id');
					$data['title']     = I('post.title');
					$data['content']   = I('post.content','','trim');
					if(empty($id) == true)
					{
						$data['createTime'] = time();
						$result = M3('web_conf_mobilehome_profile')->add($data);
					}
					else
					{
						$result = M3('web_conf_mobilehome_profile')->where(array('id'=>$id))->save($data);
					}

					break;
				case 'columns':

					$id                  = I('post.id');
					$data['imagesUrl']   = I('post.imagesUrl');
					$data['name']        = I('post.name');
					$data['description'] = I('post.description');
					$data['webUrl']      = I('post.webUrl');
					$data['sort']        = I('post.sort');
					$data['status']      = I('post.status');
					if(empty($id) == true)
					{
						$data['createTime'] = time();
						$result = M3('web_conf_mobilehome_column')->add($data);
					}
					else
					{
						$result = M3('web_conf_mobilehome_column')->where(array('id'=>$id))->save($data);
					}
					$table = 'web_conf_mobilehome_column';
					break;
				case 'columnsMain':

					$id                = I('post.id');
					$data['columnID']  = I('post.columnID');
					$data['type']      = I('post.columnType');
					$data['title']     = I('post.title');
					$data['imagesUrl'] = I('post.imagesUrl');
					$data['webUrl']    = I('post.webUrl');
					$data['sort']      = I('post.sort');

					//检测是否相同有不同的专题模板
					$mainRow = M2('web_conf_mobilehome_column_main')->where(array('columnID'=>$data['columnID']))->getField('type',true);
					if(empty($type) == false && empty($mainRow) == false && $mainRow['0'] != $data['type'])
					{
						$return['state'] = '一个专题不能有两个不同模板';
						$this->ajaxReturn($return);
					}

					if(empty($id) == true)
					{
						$data['createTime'] = time();
						$result             = M3('web_conf_mobilehome_column_main')->add($data);
					}
					else
					{
						$result             = M3('web_conf_mobilehome_column_main')->where(array('id'=>$id))->save($data);
					}

					M3('web_conf_mobilehome_column')->where(array('id'=>$data['columnID']))->save(array('type'=>$data['type']));
					$table              = 'web_conf_mobilehome_column_main';

					break;
				case 'columnsInfo':

					$id                   = I('post.id');
					$data['mainID']       = I('post.mainID');
					$data['productID']    = I('post.productID');
					$data['productTitle'] = I('post.productTitle');
					$data['imagesUrl']    = I('post.imagesUrl');
					$data['webUrl']       = I('post.webUrl');
					$data['edge']         = I('post.edge');
					$data['sort']         = I('post.sort');
					$data['sign']         = I('post.sign');
					if(empty($data['webUrl']) == true)$data['webUrl'] ='http://www.tripvip.cn/center/product/details/id/'.$data['productID'].'.html';
					if(empty($data['imagesUrl']) == true)$data['imagesUrl'] = imgUrlComplete(M2('pack_product_travel')->where(array('id'=>$data['productID']))->getField('litPic'));

					if(empty($id) == true)
					{
						$data['createTime']   = time();
						$result = M3('web_conf_mobilehome_column_info')->add($data);
					}
					else
					{
						$result = M3('web_conf_mobilehome_column_info')->where(array('id'=>$id))->save($data);
					}
					$table = 'web_conf_mobilehome_column_info';
					break;

			}

			if($result != false)
			{
				$Log = new \Model\Log();
				$Log->webconfOperation(M3($table)->getLastSql());
				$return = array('valid'=>true,'state'=>'编辑成功');
			}
			else
			{
				$return['state'] = '编辑失败';
			}
		}

		$this->ajaxReturn($return);
	}

	/**
	 * [mobilehomeUpdateSort description]
	 * @return [type] [description]
	 */
	public function mobilehomeUpdateSort()
	{
		$return = array('valid'=>false,'state'=>'请稍后重试。。。');
		if(IS_POST)
		{
			$step = I('post.step');
			$id   = I('post.id');
			$sort = I('post.sort');

			switch ($step)
			{
				case '1':
					$table = 'web_conf_mobilehome_special';
					// M3('web_conf_mobilehome_special')->where(array('id'=>$id))->save(array('sort'=>$sort));
					break;
				case '2':
					$table = 'web_conf_mobilehome_recommend';
					// M3('web_conf_mobilehome_recommend')->where(array('id'=>$id))->save(array('sort'=>$sort));
					break;
				case '3':
					$table = 'web_conf_mobilehome_destination';
					// M3('web_conf_mobilehome_destination')->where(array('id'=>$id))->save(array('sort'=>$sort));
					break;
				case '4':
					$table = 'web_conf_mobilehome_partner';
					// M3('web_conf_mobilehome_partner')->where(array('id'=>$id))->save(array('sort'=>$sort));
					break;
				case '5':
					$table = 'web_conf_mobilehome_profile';
					// M3('web_conf_mobilehome_profile')->where(array('id'=>$id))->save(array('sort'=>$sort));
					break;
				case '6':
					$table = 'web_conf_mobilehome_column';
					// M3('web_conf_mobilehome_profile')->where(array('id'=>$id))->save(array('sort'=>$sort));
					break;
				default:
					$table = 'web_conf_mobilehome_banner';
					// M3('web_conf_mobilehome_banner')->where(array('id'=>$id))->save(array('sort'=>$sort));
					break;
			}
			$result = M3($table)->where(array('id'=>$id))->save(array('sort'=>$sort));
			if($result)
			{
				$Log = new \Model\Log();
				$Log->webconfOperation(M3($table)->getLastSql());
				$return = array('valid'=>true,'state'=>'排序成功');
			}
			else
			{
				$return['state'] = '排序失败';
			}
		}
		$this->ajaxReturn($return);
	}

	/**
	 * [mobilehomeDel description]
	 * @return [type] [description]
	 */
	public function mobilehomeUpdateStatus()
	{
		$return = array('valid'=>false,'state'=>'请稍后重试。。。');
		if(IS_POST)
		{
			$step   = I('post.step');
			$id     = I('post.id');
			$status = I('post.status');
			switch ($step)
			{
				case '1':
					$table = 'web_conf_mobilehome_special';
					// M3('web_conf_mobilehome_special')->where(array('id'=>$id))->save(array('sort'=>$sort));
					break;
				case '2':
					$table = 'web_conf_mobilehome_recommend';
					// M3('web_conf_mobilehome_recommend')->where(array('id'=>$id))->save(array('sort'=>$sort));
					break;
				case '3':
					$table = 'web_conf_mobilehome_destination';
					// M3('web_conf_mobilehome_destination')->where(array('id'=>$id))->save(array('sort'=>$sort));
					break;
				case '4':
					$table = 'web_conf_mobilehome_partner';
					// M3('web_conf_mobilehome_partner')->where(array('id'=>$id))->save(array('sort'=>$sort));
					break;
				case '5':
					$table = 'web_conf_mobilehome_profile';
					// M3('web_conf_mobilehome_profile')->where(array('id'=>$id))->save(array('sort'=>$sort));
					break;
				case '6':
					$table = 'web_conf_mobilehome_column';
					// M3('web_conf_mobilehome_profile')->where(array('id'=>$id))->save(array('sort'=>$sort));
					break;
				case 'menuParent':
					$table = 'web_conf_mobilehome_column_main';
					// M3('web_conf_mobilehome_profile')->where(array('id'=>$id))->save(array('sort'=>$sort));
					break;
				case 'menuChild':
					$table = 'web_conf_mobilehome_column_info';
					// M3('web_conf_mobilehome_profile')->where(array('id'=>$id))->save(array('sort'=>$sort));
					break;
				default:
					$table = 'web_conf_mobilehome_banner';
					// M3('web_conf_mobilehome_banner')->where(array('id'=>$id))->save(array('sort'=>$sort));
					break;
			}
			$result = M3($table)->where(array('id'=>$id))->save(array('status'=>$status));
			if($result)
			{
				$Log = new \Model\Log();
				$Log->webconfOperation(M3($table)->getLastSql());
				$return = array('valid'=>true,'state'=>'更新状态成功');
			}
			else
			{
				$return['state'] = '更新状态失败';
			}
		}
		$this->ajaxReturn($return);
	}

	/**
	 * [pchome description]
	 * @return [type] [description]
	 *
	 */
	public function pchome()
	{
		$step = I('get.step',0);
		$this->step = $step;
		switch ($step)
		{
			case '1':
				$bannerList = M2('web_conf_pchome_banner')->where(array('status'=>array('neq','-1')))->order('sort')->select();
				$this->bannerList = $bannerList;
				break;
			case '2':
				$hotwordList = M2('web_conf_pchome_hotword')->where(array('status'=>array('neq','-1')))->order('sort')->select();
				$this->hotwordList = $hotwordList;
				break;
			case '3':
				$columnList = M2('web_conf_pchome_column')->where(array('status'=>array('neq','-1')))->order('sort')->select();
				$this->columnList = $columnList;
				break;
			case '4':
				$profileList = M2('company_profile')->where(array('pId'=>0,'status'=>array('neq','-1')))->order('sort')->select();
				foreach ($profileList as $key => $value)
				{
					$profileList[$key]['child'] = M2('company_profile')->where(array('pId'=>$value['id'],'status'=>array('neq','-1')))->order('sort')->select();
				}
				$this->profileList = $profileList;
				break;

			default:
				$navigateList = M2('web_conf_pchome_menu')->where(array('status'=>array('neq','-1'),'pId'=>'0'))->order('sort')->select();
				foreach ($navigateList as $key => $value)
				{
					$navigateList[$key]['child'] = M2('web_conf_pchome_menu')->where(array('status'=>array('neq','-1'),'pId'=>$value['id']))->order('sort')->select();
				}
				$this->navigateList = $navigateList;

				break;
		}
		$this->menuID   = '156';
		$this->menuName = '网站前端配置-PC端首页';
		$this->display($group['action']);
	}

	/**
	 * [pchomePost description]
	 * @return [type] [description]
	 */
	public function pchomePost()
	{
		$return = array('valid'=>false, 'state'=>'请稍后重试。。。');
		if(IS_POST)
		{
			$type = I('post.type');
			switch ($type)
			{
				case 'menu':
					$id             = I('post.id');
					$data['pId']    = I('post.menuPID');
					$data['name']   = I('post.name');
					$data['webUrl'] = I('post.webUrl');
					$data['sort']   = I('post.sort');
					$data['sign']   = I('post.sign');
					$data['status'] = I('post.status');
					if(empty($id) == true)
					{
						$data['createTime'] = time();
						$result = M3('web_conf_pchome_menu')->add($data);
					}
					else
					{
						$result = M3('web_conf_pchome_menu')->where(array('id'=>$id))->save($data);
					}

					$table = 'web_conf_pchome_menu';
					break;

				case 'homeSeo':

					$data['title']       = I('post.title');
					$data['keywords']    = I('post.keywords');
					$data['description'] = I('post.description');

					$result = M3('web_conf_pchome_menu')->where(array('id'=>'1'))->save($data);

					$table = 'web_conf_pchome_menu';
					break;
				case 'banner':

					$id                = I('post.id');
					$data['title']     = I('post.title');
					$data['imagesUrl'] = I('post.imagesUrl');
					$data['webUrl']    = I('post.webUrl');
					$data['sort']      = I('post.sort');
					$data['status']    = I('post.status');
					if(empty($id) == true)
					{
						$data['createTime'] = time();
						$result = M3('web_conf_pchome_banner')->add($data);
					}
					else
					{
						$result = M3('web_conf_pchome_banner')->where(array('id'=>$id))->save($data);
					}

					$table = 'web_conf_pchome_banner';
					break;
				case 'hotword':

					$id                = I('post.id');
					$data['name']      = I('post.name');
					$data['webUrl']    = I('post.webUrl');
					$data['sort']      = I('post.sort');
					$data['status']    = I('post.status');
					if(empty($id) == true)
					{
						$data['createTime'] = time();
						$result = M3('web_conf_pchome_hotword')->add($data);
					}
					else
					{
						$result = M3('web_conf_pchome_hotword')->where(array('id'=>$id))->save($data);
					}
					$table = 'web_conf_pchome_hotword';
					break;

				case 'columns':

					$id                  = I('post.id');
					$data['imagesUrl']   = I('post.imagesUrl');
					$data['name']        = I('post.name');
					$data['description'] = I('post.description');
					$data['webUrl']      = I('post.webUrl');
					$data['sort']        = I('post.sort');
					$data['status']      = I('post.status');
					if(empty($id) == true)
					{
						$data['createTime'] = time();
						$result = M3('web_conf_pchome_column')->add($data);
					}
					else
					{
						$result = M3('web_conf_pchome_column')->where(array('id'=>$id))->save($data);
					}
					$table = 'web_conf_pchome_column';
					break;
				case 'columnsMain':

					$id                = I('post.id');
					$data['columnID']  = I('post.columnID');
					$data['type']      = I('post.columnType');
					$data['title']     = I('post.title');
					$data['imagesUrl'] = I('post.imagesUrl');
					$data['webUrl']    = I('post.webUrl');
					$data['sort']      = I('post.sort');

					//检测是否相同有不同的专题模板
					$mainRow = M2('web_conf_pchome_column_main')->where(array('columnID'=>$data['columnID']))->getField('type',true);
					if(empty($type) == false && empty($mainRow) == false && $mainRow['0'] != $data['type'])
					{
						$return['state'] = '一个专题不能有两个不同模板';
						$this->ajaxReturn($return);
					}

					if(empty($id) == true)
					{
						$data['createTime'] = time();
						$result             = M3('web_conf_pchome_column_main')->add($data);
					}
					else
					{
						$result             = M3('web_conf_pchome_column_main')->where(array('id'=>$id))->save($data);
					}

					M3('web_conf_pchome_column')->where(array('id'=>$data['columnID']))->save(array('type'=>$data['type']));
					$table              = 'web_conf_pchome_column_main';

					break;
				case 'columnsInfo':

					$id                   = I('post.id');
					$data['mainID']       = I('post.mainID');
					$data['productID']    = I('post.productID');
					$data['productTitle'] = I('post.productTitle');
					$data['imagesUrl']    = I('post.imagesUrl');
					$data['webUrl']       = I('post.webUrl');
					$data['edge']         = I('post.edge');
					$data['sort']         = I('post.sort');
					$data['sign']         = I('post.sign');
					if(empty($data['webUrl']) == true)$data['webUrl'] ='http://www.tripvip.cn/center/product/details/id/'.$data['productID'].'.html';
					if(empty($data['imagesUrl']) == true)$data['imagesUrl'] = imgUrlComplete(M2('pack_product_travel')->where(array('id'=>$data['productID']))->getField('litPic'));

					if(empty($id) == true)
					{
						$data['createTime']   = time();
						$result = M3('web_conf_pchome_column_info')->add($data);
					}
					else
					{
						$result = M3('web_conf_pchome_column_info')->where(array('id'=>$id))->save($data);
					}
					$table = 'web_conf_pchome_column_info';
					break;
				case 'profile':
					$data['title']   = I('post.title');
					$data['pId']     = I('post.pId');
					$data['content'] = I('post.content','','trim');
					$data['content'] = I('post.description');
					$data['content'] = I('post.keyWords');
					$data['content'] = I('post.sort');
					$data['content'] = I('post.status');

					$profileRow = M3('company_profile')->where(array('id'=>$id))->find();
					if(empty($profileRow) == true)
					{
						$data['createTime'] = time();
						$result = M3('company_profile')->add($data);
					}
					else
					{
						$result = M3('company_profile')->where(array('id'=>$id))->save($data);
					}

					$table = 'company_profile';
					break;

			}
			if($result != false)
			{
				$Log = new \Model\Log();
				$Log->webconfOperation(M3($table)->getLastSql());
				$return = array('valid'=>true, 'state'=>'编辑成功');
			}
			else
			{
				$return['state'] = '编辑失败';
			}
		}
		else
		{
			$return['state'] = '请求出错。。。';
		}
		$this->ajaxReturn($return);
	}

	/**
	 * [pchomecolumnstyle description]
	 * @return [type] [description]
	 */
	public function pchomecolumnstyle()
	{
		$id = I('get.id');
		$this->id = $id;
		$columnRow = M2('web_conf_pchome_column')->where(array('id'=>$id))->find();
		if($columnRow == false)$this->error('此栏目不存在！');
		$columnRow['parent'] = M2('web_conf_pchome_column_main')->where(array('columnID'=>$columnRow['id'],'type'=>$columnRow['type']))->order('sort')->select();
		foreach ($columnRow['parent'] as $kp => $vp)
		{
			$columnRow['parent'][$kp]['child'] = M2('web_conf_pchome_column_info')->where(array('mainID'=>$vp['id']))->select();
			foreach ($columnRow['parent'][$kp]['child'] as $kc => $vc)
			{
				$productRow = M2('pack_product_travel')->field('price,categoryInterestID')->where(array('id'=>$vc['productID']))->find();
				$columnRow['parent'][$kp]['child'][$kc]['price'] = $productRow['price'];

				$categoryInterestArr = explode('|', $productRow['categoryInterestID']);
				$labelCount          = count($categoryInterestArr);
				$labelNameArr        = array();
				for ($i=0; $i < $labelCount; $i++)
				{
					$labelNameArr[$i] = M2('label_class')->where(array('id'=>$categoryInterestArr[$i]))->getField('name');

				}

				$columnRow['parent'][$kp]['child'][$kc]['labelName'] = implode('|',$labelNameArr);
				unset($categoryInterestArr);
				unset($labelNameArr);
				switch ($vc['sign'])
				{
					case '1':
						$signName = '新品';
						break;
					case '2':
						$signName = '爆款';
						break;
					case '3':
						$signName = '特价';
						break;
				}

				$columnRow['parent'][$kp]['child'][$kc]['signName']  = $signName;
				unset($signName);

				if(empty($columnRow['parent'][$kp]['child'][$kc]['wenUrl']) == true && empty($columnRow['parent'][$kp]['child'][$kc]['productID']) == false)
				{
					$columnRow['parent'][$kp]['child'][$kc]['wenUrl'] = "http://www.tripvip.cn/center/product/details/id/".$columnlist[$key]['parent'][$kp]['child'][$kc]['productID'].".html";
				}
				unset($productRow);
			}
		}
		$this->columnRow = $columnRow;
		// var_dump($columnRow);
		$this->menuID   = '156';
		$this->menuName = 'PC端栏目模板——'.$columnRow['name'];
		$this->display();
	}

	/**
	 * [pchomeUpdateSort description]
	 * @return [type] [description]
	 */
	public function pchomeUpdateSort()
	{
		$return = array('valid'=>false, 'state'=>'请稍后重试。。。');
		if(IS_POST)
		{
			$id   = I('post.id');
			$step = I('post.step');
			$sort = I('post.sort');
			switch ($step)
			{
				case '1':
					$table = 'web_conf_pchome_banner';
					break;

				case '2':

					$table = 'web_conf_pchome_hotword';
					break;
				case '3':

					$table = 'web_conf_pchome_column';
					break;
				case '4':

					$table = 'company_profile';
					break;
				default:

					$table = 'web_conf_pchome_menu';
					break;

			}
			$result = M3($table)->where(array('id'=>$id))->save(array('sort'=>$sort));
			$Log = new \Model\Log();
			$Log->webconfOperation(M3($table)->getLastSql());
			if($result != false)
			{
				$return = array('valid'=>true, 'state'=>'排序成功');
			}
			else
			{
				$return['state'] = '排序失败';
			}
		}
		else
		{
			$return['state'] = '请求出错。。。';
		}
		$this->ajaxReturn($return);
	}

	/**
	 * [pchomeUpdateStatus description]
	 * PC首页状态更新
	 * @return [type] [description]
	 */
	public function pchomeUpdateStatus()
	{
		$return = array('valid'=>false,'state'=>'请稍后重试。。。');
		if(IS_POST)
		{
			$step   = I('post.step');
			$id     = I('post.id');
			$status = I('post.status');
			switch ($step)
			{
				case '1':
					$table = 'web_conf_pchome_banner';
					break;
				case '2':
					$table = 'web_conf_pchome_hotword';
					break;
				case '3':
					$table = 'web_conf_pchome_column';
					break;
				case '4':
					$table = 'company_profile';
					break;
				case 'menuParent':
					$table = 'web_conf_pchome_column_main';
					break;
				case 'menuChild':
					$table = 'web_conf_pchome_column_info';
					break;
				default:
					$table = 'web_conf_pchome_menu';
					break;
			}
			$result = M3($table)->where(array('id'=>$id))->save(array('status'=>$status));
			if($result)
			{

				$Log = new \Model\Log();
				$Log->webconfOperation(M3($table)->getLastSql());
				$return = array('valid'=>true,'state'=>'删除成功');
			}
			else
			{
				$return['state'] = '删除失败';
			}
		}
		$this->ajaxReturn($return);
	}
	/**
	 * [getAjaxBind description]
	 * @return [type] [description]
	 */
	public function getAjaxBind()
	{
		$return = array('valid'=>false,'state'=>'请稍后重试。。。');
		if(IS_POST)
		{
			$type = I('post.type');
			switch ($type)
			{
				case 'product':
					$id     = I('post.id');
					$result = M2('pack_product_travel')->where(array('id'=>$id,array('status'=>'1')))->find();

					break;

				case 'destination':
					$id     = I('post.id');
					$result = M2('destination')->where(array('id'=>$id))->find();

					break;

			}

			if($result != false)
			{
				$return = array('valid'=>true,'state'=>'SUCCESS');

				if(empty($result['title']) == true)
				{
					$return['info']['title'] = $result['name'];
				}
				else
				{
					$return['info']['title'] = $result['title'];
				}
			}
			else
			{
				$return['state'] = '没有找到对应的数据';
			}
		}

		$this->ajaxReturn($return);
	}

	/**
	 * [profileLayer description]
	 * @return [type] [description]
	 */
	public function profileLayer()
	{
		layout(false);

		$id         = I('get.id');
		$this->id   = $id;
		$type       = I('get.type');
		$this->type = $type;
		switch ($type)
		{
			case 'mobile':
				$info = M2('web_conf_mobilehome_profile')->where(array('id'=>$id))->find();
				break;
			case 'pc':
				$info = M2('company_profile')->where(array('id'=>$id))->find();
				$info['title'] = $info['cName'];
				break;
		}

		$this->info = $info;

		$this->display();
	}

	/**
	 * [profileLayerPost description]
	 * @return [type] [description]
	 */
	public function profileLayerPost()
	{
		$return = array('valid'=>false,'state'=>'请稍后重试...');

		$id   = I('get.id');
		$type = I('get.type');
		if(IS_POST)
		{
			switch ($type)
			{
				case 'mobile':
					$data['title']   = I('post.title');
					$data['content'] = I('post.content','','trim');
					$data['content'] = I('post.description');
					$data['content'] = I('post.keyWords');

					$profileRow = M3('web_conf_mobilehome_profile')->where(array('id'=>$id))->find();
					if(empty($profileRow) == true)
					{
						$data['createTime'] = time();
						$result = M3('web_conf_mobilehome_profile')->add($data);
					}
					else
					{
						$result = M3('web_conf_mobilehome_profile')->where(array('id'=>$id))->save($data);
					}
					$table = 'web_conf_mobilehome_profile';
					break;
				case 'pc':

					$data['cName']   = I('post.title');
					$data['pId']     = I('get.pId',0);
					$data['content'] = I('post.content','','trim');
					$data['content'] = I('post.description');
					$data['content'] = I('post.keyWords');
					$data['content'] = I('post.sort');
					$data['content'] = I('post.status');

					$profileRow = M3('company_profile')->where(array('id'=>$id))->find();
					if(empty($profileRow) == true)
					{
						$data['createTime'] = time();
						$result = M3('company_profile')->add($data);
					}
					else
					{
						$result = M3('company_profile')->where(array('id'=>$id))->save($data);
					}

					$table = 'company_profile';
					break;
			}

			if($result != false)
			{
				$Log = new \Model\Log();
				$Log->webconfOperation(M3($table)->getLastSql());
				$return = array('valid'=>true,'state'=>'编辑成功');
			}
			else
			{
				$return['state'] = '编辑失败';
			}
		}

		$this->ajaxReturn($return);
	}
	/**
	 * [timetodate description]
	 * @return [type] [description]
	 */
	public function timetodate($time,$format)
	{
		if($time == false)
		{
			$date = '';
		}
		else
		{
			$date = date($format,$time);
		}
		return $date;
	}

}

function imgUrlComplete($url)
{

	if(strstr($url,'http://www.tripvip.cn') == false && empty($url) == false)
	{
		return 'http://www.tripvip.cn'.$url;
	}
	else
	{
		return $url;
	}
}


?>